//
//  UIView+Util.m
//  CarUser
//
//  Created by ayi on 2019/1/10.
//  Copyright © 2019 王森林. All rights reserved.
//

#import "UIView+Util.h"

@implementation UIView (Util)

//_typeLabel = [UILabel new];
//_typeLabel.textColor = Common_Text_TextfieldColor;
//_typeLabel.textAlignment = NSTextAlignmentCenter;
//_typeLabel.font = FONT_SIZE(12);
//_typeLabel.layer.borderWidth = 1;
//_typeLabel.layer.cornerRadius = 6;
//_typeLabel.layer.masksToBounds = YES;
//_typeLabel.layer.borderColor = Common_Head_Color.CGColor;
+ (NSMutableAttributedString *)imgAttirbuteStrWith:(NSString *)tipsStr{
    UILabel *tipslab = [UILabel customInitLabWithFont:12 andTextColor:Common_Text_TextfieldColor andAlign:NSTextAlignmentCenter];
    CGSize size = [CommonMethod labWidthFromStr:tipsStr andFont:tipslab.font andWidth:BOUNDWIDTH];
    tipslab.frame = CGRectMake(0, 0, 38, 18);
    tipslab.layer.borderColor = Common_TextLowColor.CGColor;
    tipslab.layer.borderWidth = 1;
    tipslab.layer.cornerRadius = 6;
    tipslab.text = tipsStr;
    UIImage *img = [self imageWithUIView:tipslab];
    
    NSTextAttachment* textAttachment = [[NSTextAttachment alloc] init];
    textAttachment.image = img;
    textAttachment.bounds = CGRectMake(0, -2, size.width + 10, ceilf(tipslab.font.lineHeight) + 6);
    NSAttributedString* imageAttachment = [NSAttributedString attributedStringWithAttachment:textAttachment];
    
    return imageAttachment.mutableCopy;
}

+ (UIImage*) imageWithUIView:(UIView*) view{
    UIGraphicsBeginImageContextWithOptions(view.bounds.size,NO,5);
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    [view.layer renderInContext:ctx];
    UIImage* tImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return tImage;
}


@end
